// pages/user/authorize/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        avatar: '',
        nickname:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        wx.$http.get('member/getUserAuth', {}, {
            loading: true
        }).then((res) => {
            this.setData({
                avatar:res.data.avatar,
                nickname:res.data.nickname
            })
        });
    },

    // 选择头像
    onChooseAvatar(e) {
        let _this = this;
        const globalData = getApp().globalData;
        wx.uploadFile({
            url: 'https://baihezhifa.itengfan.com/api/upload/image',
            filePath: e.detail.avatarUrl,
            name: 'iFile',
            header: { //HTTP 请求 Header，Header 中不能设置 Referer
                Authorization: 'Bearer token' //权限
            },
            formData: {
                'session_id': 666
            },
            success: function (res) {
                let result = typeof res.data === "object" ? res.data : JSON.parse(res.data);
                console.log("上传图片")
                console.log(result)
                if (result.code === 1) {
                    _this.setData({
                        avatar: result.data.url
                    })
                }
            },
            complete: function (res) {
                let result = typeof res.data === "object" ? res.data : JSON.parse(res.data);
                _this.setData({
                    avatar: result.data.url
                })
            }
        });

    },
    formSubmit(e) {
        let avatar = this.data.avatar
        let name = e.detail.value.nickname;
        wx.$http.get('member/editInfo', {'avatar':avatar,'name':name}, {
            loading: true
        }).then((res) => {
            wx.navigateBack();
        });
    }
})